package com.jspgou.cms.dao.impl;

import org.apache.commons.lang.StringUtils;
import org.hibernate.Criteria;
import org.springframework.stereotype.Repository;

import com.jspgou.common.hibernate3.Finder;
import com.jspgou.common.hibernate3.HibernateBaseDao;
import com.jspgou.common.page.Pagination;
import com.jspgou.cms.dao.PopularityGroupDao;
import com.jspgou.cms.entity.PopularityGroup;

@Repository
public class PopularityGroupDaoImpl extends HibernateBaseDao<PopularityGroup, Long> implements PopularityGroupDao {
	public Pagination getPage(Long storeId,int pageNo, int pageSize) {
		Finder f = Finder.create("from PopularityGroup bean where 1=1");
		if (storeId != null) {
			f.append(" and bean.store.id=:storeId");
			f.setParam("storeId", storeId);
		}else{
			f.append(" and bean.store.id is null");
		}
		return find(f, pageNo, pageSize);
	}

	public PopularityGroup findById(Long id) {
		PopularityGroup entity = get(id);
		return entity;
	}

	public PopularityGroup save(PopularityGroup bean) {
		getSession().save(bean);
		return bean;
	}

	public PopularityGroup deleteById(Long id) {
		PopularityGroup entity = super.get(id);
		if (entity != null) {
			getSession().delete(entity);
		}
		return entity;
	}
	
	@Override
	protected Class<PopularityGroup> getEntityClass() {
		return PopularityGroup.class;
	}
}